library(shiny)
library(tidyverse)
## ── Attaching packages ─────────────────────────────────────── tidyverse 1.3.2 ──
## ✔ ggplot2 3.4.0 ✔ purrr 0.3.5
## ✔ tibble 3.1.8 ✔ dplyr 1.0.10
## ✔ tidyr 1.2.1 ✔ stringr 1.4.1
## ✔ readr 2.1.3 ✔ forcats 0.5.2
## ── Conflicts ────────────────────────────────────────── tidyverse_conflicts() ──
## ✖ dplyr::filter() masks stats::filter()
## ✖ dplyr::lag() masks stats::lag()
geo_eccc <- read.csv("TEST-GOE-Monitor.csv", header = TRUE, sep = ",")
Sites_eccc <- read.csv("SiteDetails-TEST-GOE-Monitor.csv", header = TRUE, sep = ",")
colnames(geo_eccc)
## [1] "Subregion" "Site"
## [3] "Proportion_of_native_species" "Cultural_species_richness"
## [5] "Exotic_species" "Trampling"
## [7] "Herbivory" "Composite_Index"
colnames(Sites_eccc)
## [1] "Subregion" "Site" "Land.Manager"
## [4] "Main.Restoration.Type" "Restoration.Intensity" "Area.ha"
## [7] "Lat" "Lng"
str(geo_eccc)
## 'data.frame': 24 obs. of 8 variables:
## $ Subregion : chr "Gulf Islands" "Gulf Islands" "Gulf Islands" "Gulf Islands" ...
## $ Site : chr "Anniversary Island" "AVNR" "Brackman Island" "Crows Nest" ...
## $ Proportion_of_native_species: num 0.94 0.55 0.77 0.66 0.75 0.53 0.45 0.65 0.62 0.58 ...
## $ Cultural_species_richness : num 2.71 1.3 2.8 1.07 3.6 0.8 0.42 2 3.6 2.33 ...
## $ Exotic_species : num 0.17 57.19 11.17 31.51 8.8 ...
## $ Trampling : num 5 4.7 5.4 1.64 12.2 ...
## $ Herbivory : num 1.14 36.5 0 26.71 0.1 ...
## $ Composite_Index : num 1.8 0.6 2 1 1.6 0.8 0.2 1.4 1 1 ...
str(Sites_eccc)
## 'data.frame': 24 obs. of 8 variables:
## $ Subregion : chr "Saanich Peninsula" "Saanich Peninsula" "Saanich Peninsula" "Saanich Peninsula" ...
## $ Site : chr " Gore Park" " Highrock Park" " Mill Hill Park" " Oak Haven Park" ...
## $ Land.Manager : chr " Central Saanich" " City of Esquimalt" " CRD" " CRD" ...
## $ Main.Restoration.Type: chr " invasive removal" " invasive removal" " invasive removal" " invasive removal" ...
## $ Restoration.Intensity: chr " moderate" " low" " high" " high" ...
## $ Area.ha : num 0.74 2.88 16.66 3.16 3.36 ...
## $ Lat : num 48.5 48.4 48.5 48.6 48.5 ...
## $ Lng : num -123 -123 -123 -123 -123 ...
length(unique(geo_eccc$Site))
## [1] 24
length(unique(Sites_eccc$Site))
## [1] 24
# tidyverse
# https://stackoverflow.com/questions/68989228/sort-dataframe-by-column-value-r
Sites_eccc_1 <- Sites_eccc %>% arrange(Site)
geo_eccc_1 <- geo_eccc %>% arrange(Site)
geo_eccc_sites <- cbind(Sites_eccc_1, geo_eccc_1)
names(geo_eccc_sites)
## [1] "Subregion" "Site"
## [3] "Land.Manager" "Main.Restoration.Type"
## [5] "Restoration.Intensity" "Area.ha"
## [7] "Lat" "Lng"
## [9] "Subregion" "Site"
## [11] "Proportion_of_native_species" "Cultural_species_richness"
## [13] "Exotic_species" "Trampling"
## [15] "Herbivory" "Composite_Index"
# https://stackoverflow.com/questions/7072159/how-do-you-remove-columns-from-a-data-frame
geo_eccc_sites_1 <- geo_eccc_sites[c(-9,-10)]
names(geo_eccc_sites_1)
## [1] "Subregion" "Site"
## [3] "Land.Manager" "Main.Restoration.Type"
## [5] "Restoration.Intensity" "Area.ha"
## [7] "Lat" "Lng"
## [9] "Proportion_of_native_species" "Cultural_species_richness"
## [11] "Exotic_species" "Trampling"
## [13] "Herbivory" "Composite_Index"
names(geo_eccc_sites_1)
## [1] "Subregion" "Site"
## [3] "Land.Manager" "Main.Restoration.Type"
## [5] "Restoration.Intensity" "Area.ha"
## [7] "Lat" "Lng"
## [9] "Proportion_of_native_species" "Cultural_species_richness"
## [11] "Exotic_species" "Trampling"
## [13] "Herbivory" "Composite_Index"
names(geo_eccc_sites_1)
## [1] "Subregion" "Site"
## [3] "Land.Manager" "Main.Restoration.Type"
## [5] "Restoration.Intensity" "Area.ha"
## [7] "Lat" "Lng"
## [9] "Proportion_of_native_species" "Cultural_species_richness"
## [11] "Exotic_species" "Trampling"
## [13] "Herbivory" "Composite_Index"
# names(my_data)[names(my_data) == "Sepal.Length"] <- "sepal_length"
names(geo_eccc_sites_1)[names(geo_eccc_sites_1) == "Land.Manager"] <- "Land_Manager"
names(geo_eccc_sites_1)[names(geo_eccc_sites_1) == "Main.Restoration.Type"] <- "Main_Restoration_Type"
names(geo_eccc_sites_1)[names(geo_eccc_sites_1) == "Restoration.Intensity"] <- "Restoration_Intensity"
names(geo_eccc_sites_1)[names(geo_eccc_sites_1) == "Area.ha"] <- "Area_ha"
names(geo_eccc_sites_1)
## [1] "Subregion" "Site"
## [3] "Land_Manager" "Main_Restoration_Type"
## [5] "Restoration_Intensity" "Area_ha"
## [7] "Lat" "Lng"
## [9] "Proportion_of_native_species" "Cultural_species_richness"
## [11] "Exotic_species" "Trampling"
## [13] "Herbivory" "Composite_Index"
write.csv(geo_eccc_sites_1, "geo_eccc_all_site_data.csv", row.names = FALSE)
Percentage_of_native_species <- scales::percent(geo_eccc$Proportion_of_native_species)
Percentage_of_native_species
## [1] "94%" "55%" "77%" "66%" "75%" "53%" "45%" "65%" "62%" "58%" "45%" "67%"
## [13] "62%" "61%" "32%" "64%" "49%" "41%" "47%" "34%" "34%" "44%" "54%" "37%"
Percentage_ns <- geo_eccc$Proportion_of_native_species * 100
Percentage_ns
## [1] 94 55 77 66 75 53 45 65 62 58 45 67 62 61 32 64 49 41 47 34 34 44 54 37
data
# https://sparkbyexamples.com/r-programming/add-column-to-dataframe-in-r/
# geo_eccc_1 <- cbind(geo_eccc, Percentage_of_native_species)
# geo_eccc_1
geo_eccc_1 <- cbind(geo_eccc, Percentage_ns)
geo_eccc_1
## Subregion Site Proportion_of_native_species
## 1 Gulf Islands Anniversary Island 0.94
## 2 Gulf Islands AVNR 0.55
## 3 Gulf Islands Brackman Island 0.77
## 4 Gulf Islands Crows Nest 0.66
## 5 Gulf Islands Dock Islet N 0.75
## 6 Gulf Islands Eagle Islet 0.53
## 7 Gulf Islands Mt Maxwell 0.45
## 8 Gulf Islands Owl Islet 0.65
## 9 Gulf Islands Reay Islet 0.62
## 10 Gulf Islands Retreat Island 0.58
## 11 Gulf Islands Rum Islet 0.45
## 12 Gulf Islands SISCENEM 0.67
## 13 Saanich Peninsula Bear Hill Park 0.62
## 14 Saanich Peninsula Camas Hill 0.61
## 15 Saanich Peninsula Gonzales Hill Park 0.32
## 16 Saanich Peninsula Gore Park 0.64
## 17 Saanich Peninsula Highrock Park 0.49
## 18 Saanich Peninsula Mill Hill Park 0.41
## 19 Saanich Peninsula Oak Haven Park 0.47
## 20 Saanich Peninsula Scafe Hill 0.34
## 21 Saanich Peninsula Seymour Hill 0.34
## 22 Saanich Peninsula Stewart Hill 0.44
## 23 Saanich Peninsula Trial Island 0.54
## 24 Saanich Peninsula Uplands Park 0.37
## Cultural_species_richness Exotic_species Trampling Herbivory Composite_Index
## 1 2.71 0.17 5.00 1.14 1.8
## 2 1.30 57.19 4.70 36.50 0.6
## 3 2.80 11.17 5.40 0.00 2.0
## 4 1.07 31.51 1.64 26.71 1.0
## 5 3.60 8.80 12.20 0.10 1.6
## 6 0.80 28.25 16.60 0.00 0.8
## 7 0.42 64.30 10.00 6.00 0.2
## 8 2.00 27.72 10.67 0.67 1.4
## 9 3.60 11.51 11.00 8.00 1.0
## 10 2.33 33.00 32.33 0.00 1.0
## 11 1.00 73.21 22.20 70.80 0.0
## 12 3.40 16.12 12.80 0.50 1.6
## 13 1.86 24.46 7.57 9.50 1.0
## 14 2.43 27.19 7.71 4.71 1.4
## 15 1.00 83.16 10.40 1.20 0.4
## 16 4.40 7.35 6.20 1.60 1.6
## 17 1.60 37.10 8.20 1.20 1.0
## 18 1.56 46.33 14.33 25.67 0.4
## 19 1.50 34.60 1.88 12.75 1.0
## 20 1.40 55.35 10.20 1.40 0.4
## 21 2.20 65.99 9.20 0.20 0.8
## 22 1.00 79.56 4.80 0.80 0.6
## 23 3.57 30.73 2.00 0.14 1.6
## 24 1.45 49.38 2.36 5.82 1.0
## Percentage_ns
## 1 94
## 2 55
## 3 77
## 4 66
## 5 75
## 6 53
## 7 45
## 8 65
## 9 62
## 10 58
## 11 45
## 12 67
## 13 62
## 14 61
## 15 32
## 16 64
## 17 49
## 18 41
## 19 47
## 20 34
## 21 34
## 22 44
## 23 54
## 24 37
colnames(geo_eccc_1)
## [1] "Subregion" "Site"
## [3] "Proportion_of_native_species" "Cultural_species_richness"
## [5] "Exotic_species" "Trampling"
## [7] "Herbivory" "Composite_Index"
## [9] "Percentage_ns"
site_natsp <- ggplot(geo_eccc,
aes(x = Site, y = Percentage_ns)) +
geom_point(shape = 18, size = 2) +
theme_minimal() + #get rid of grey background and tick marks
theme(legend.position="none") + #remove legend
theme(axis.text.x = element_text(angle = 25, vjust = 1, hjust=1, size = 7)) +
labs(title='Ploting Site by Percentage Native Species',
subtitle='ECCC',
caption = "Chart by Wendy Anthony \n 2025-08-04")
site_natsp
site_natsp <- ggplot(geo_eccc,
aes(x = Site, y = Composite_Index)) +
geom_point(shape = 18, size = 2) +
theme_minimal() + #get rid of grey background and tick marks
theme(legend.position="none") + #remove legend
theme(axis.text.x = element_text(angle = 25, vjust = 1, hjust=1, size = 7)) +
labs(title='Ploting Site by Composite Index',
subtitle='ECCC',
caption = "Chart by Wendy Anthony \n 2025-08-04")
site_natsp
subregion_exsp <- ggplot(geo_eccc,
aes(x = Subregion, y = Exotic_species)) +
geom_violin(fill = "seagreen2") +
geom_boxplot(width = 0.1, fill = "sandybrown") +
theme_minimal() + #get rid of grey background and tick marks
theme(legend.position="none") + #remove legend
theme(axis.text.x = element_text(angle = 25, vjust = 1, hjust=1, size = 7)) +
labs(title='Ploting Subregion by Exotic_species',
subtitle='ECCC',
caption = "Chart by Wendy Anthony \n 2025-08-04")
subregion_exsp
subregion_natsp <- ggplot(geo_eccc_1,
aes(x = Subregion, y = Percentage_ns)) +
geom_violin(fill = "seagreen2") +
geom_boxplot(width = 0.1, fill = "sandybrown") +
theme_minimal() + #get rid of grey background and tick marks
theme(legend.position="none") + #remove legend
theme(axis.text.x = element_text(angle = 25, vjust = 1, hjust=1, size = 7)) +
labs(title='Ploting Subregion by Proportion_of_native_species',
subtitle='ECCC',
caption = "Chart by Wendy Anthony \n 2025-08-04")
subregion_natsp
colnames(geo_eccc_1)
## [1] "Subregion" "Site"
## [3] "Proportion_of_native_species" "Cultural_species_richness"
## [5] "Exotic_species" "Trampling"
## [7] "Herbivory" "Composite_Index"
## [9] "Percentage_ns"
Anniversary_Island <- geo_eccc_1[1, ]
Anniversary_Island
## Subregion Site Proportion_of_native_species
## 1 Gulf Islands Anniversary Island 0.94
## Cultural_species_richness Exotic_species Trampling Herbivory Composite_Index
## 1 2.71 0.17 5 1.14 1.8
## Percentage_ns
## 1 94
Uplands <- geo_eccc_1[24, ]
Uplands
## Subregion Site Proportion_of_native_species
## 24 Saanich Peninsula Uplands Park 0.37
## Cultural_species_richness Exotic_species Trampling Herbivory Composite_Index
## 24 1.45 49.38 2.36 5.82 1
## Percentage_ns
## 24 37
Gonzales <- geo_eccc_1[15, ]
Gonzales
## Subregion Site Proportion_of_native_species
## 15 Saanich Peninsula Gonzales Hill Park 0.32
## Cultural_species_richness Exotic_species Trampling Herbivory Composite_Index
## 15 1 83.16 10.4 1.2 0.4
## Percentage_ns
## 15 32
Gonzales <- Gonzales[, -c(1,2,3)]
Gonzales
## Cultural_species_richness Exotic_species Trampling Herbivory Composite_Index
## 15 1 83.16 10.4 1.2 0.4
## Percentage_ns
## 15 32
Gonzales_long <- Gonzales %>% pivot_longer(everything(), names_to = "variable", values_to = "value")
Gonzales_long
## # A tibble: 6 × 2
## variable value
## <chr> <dbl>
## 1 Cultural_species_richness 1
## 2 Exotic_species 83.2
## 3 Trampling 10.4
## 4 Herbivory 1.2
## 5 Composite_Index 0.4
## 6 Percentage_ns 32
# delete first 2 columns as they can't be characters also Percentage
Uplands <- Uplands[, -c(1,2,3)]
Uplands
## Cultural_species_richness Exotic_species Trampling Herbivory Composite_Index
## 24 1.45 49.38 2.36 5.82 1
## Percentage_ns
## 24 37
Uplands_long <- Uplands %>% pivot_longer(everything(), names_to = "variable", values_to = "value")
Uplands_long
## # A tibble: 6 × 2
## variable value
## <chr> <dbl>
## 1 Cultural_species_richness 1.45
## 2 Exotic_species 49.4
## 3 Trampling 2.36
## 4 Herbivory 5.82
## 5 Composite_Index 1
## 6 Percentage_ns 37
Uplands_long_plot <- ggplot(Uplands_long,
aes(x = variable, y = value)) +
# https://www.sthda.com/english/wiki/ggplot2-axis-scales-and-transformations
ylim(0, 100) +
geom_point() +
theme_minimal() + #get rid of grey background and tick marks
theme(legend.position="none") + #remove legend
theme(axis.text.x = element_text(angle = 25, vjust = 1, hjust=1, size = 7)) +
labs(title='Ploting Uplands Variables',
subtitle='ECCC',
caption = "Chart by Wendy Anthony \n 2025-08-04")
Uplands_long_plot
Gonzales_long_plot <- ggplot(Gonzales_long,
aes(x = variable, y = value)) +
# https://www.sthda.com/english/wiki/ggplot2-axis-scales-and-transformations
ylim(0, 100) +
geom_point() +
theme_minimal() + #get rid of grey background and tick marks
theme(legend.position="none") + #remove legend
theme(axis.text.x = element_text(angle = 25, vjust = 1, hjust=1, size = 7)) +
labs(title='Ploting Gonzales Variables',
subtitle='ECCC',
caption = "Chart by Wendy Anthony \n 2025-08-04")
Gonzales_long_plot
compare_bar_uplands <- ggplot(Uplands_long,
aes(x = variable, y = value)) +
# Exotic_species
# https://www.sthda.com/english/wiki/ggplot2-axis-scales-and-transformations
ylim(0, 100) +
geom_bar(stat = "identity", fill = "seagreen") +
theme_minimal() + #get rid of grey background and tick marks
theme(legend.position="none") + #remove legend
theme(axis.text.x = element_text(angle = 25, vjust = 1, hjust=1, size = 7)) +
labs(title='Comparinging Uplands Variables',
subtitle='ECCC',
caption = "Chart by Wendy Anthony \n 2025-08-08")
compare_bar_uplands
colnames(geo_eccc_1)
## [1] "Subregion" "Site"
## [3] "Proportion_of_native_species" "Cultural_species_richness"
## [5] "Exotic_species" "Trampling"
## [7] "Herbivory" "Composite_Index"
## [9] "Percentage_ns"
geo_eccc_1_filter <- filter(geo_eccc_1, Site %in% c("Uplands Park", "Trial Island"))
geo_eccc_2_filter <- filter(geo_eccc_1, Site %in% c("Gulf Islands", "Saanich Peninsula"))
compare_col_uplands <- ggplot(geo_eccc_1_filter,
aes(Site, fill = Exotic_species)) + geom_bar(position = "dodge", alpha = 0.5) +
theme_minimal() + #get rid of grey background and tick marks
theme(legend.position="none") + #remove legend
theme(axis.text.x = element_text(angle = 25, vjust = 1, hjust=1, size = 7)) +
labs(title='Comparinging Uplands Variables',
subtitle='ECCC',
caption = "Chart by Wendy Anthony \n 2025-08-08")
compare_col_uplands
# colnames(geo_eccc_1)
library(shiny)
library(miniUI)
library(ggplot2)
lmGadget <- function(data, xvar, yvar) {
ui <- miniPage(
gadgetTitleBar("Interactive lm"),
miniContentPanel(
fillRow(flex = c(NA, 1),
fillCol(width = "100px",
selectInput("degree", "Polynomial degree", c(1, 2, 3, 4))
),
plotOutput("plot1",
height = "100%",
click = "plot1_click",
brush = brushOpts(
id = "plot1_brush"
)
)
)
),
miniButtonBlock(
actionButton("exclude_toggle", "Toggle points"),
actionButton("exclude_reset", "Reset")
)
)
server <- function(input, output) {
# For storing which rows have been excluded
vals <- reactiveValues(
keeprows = rep(TRUE, nrow(data))
)
output$plot1 <- renderPlot({
req(input$degree)
formula <- as.formula(paste0("y ~ poly(x, degree = ", input$degree, ")"))
# Plot the kept and excluded points as two separate data sets
keep <- data[ vals$keeprows, , drop = FALSE]
exclude <- data[!vals$keeprows, , drop = FALSE]
ggplot(keep, aes_string(xvar, yvar)) + geom_point() +
geom_smooth(method = lm, formula = formula, fullrange = TRUE, color = "gray50") +
geom_point(data = exclude, fill = NA, color = "black", alpha = 0.25) +
coord_cartesian(xlim = range(data[[xvar]]), ylim = range(data[[yvar]])) +
theme_bw(base_size = 14)
})
# Toggle points that are clicked
observeEvent(input$plot1_click, {
res <- nearPoints(data, input$plot1_click, allRows = TRUE)
vals$keeprows <- xor(vals$keeprows, res$selected_)
})
# Toggle points that are brushed, when button is clicked
observeEvent(input$exclude_toggle, {
res <- brushedPoints(data, input$plot1_brush, allRows = TRUE)
vals$keeprows <- xor(vals$keeprows, res$selected_)
})
# Reset all points
observeEvent(input$exclude_reset, {
vals$keeprows <- rep(TRUE, nrow(data))
})
# Handle the Done button being pressed.
observeEvent(input$done, {
# Replace x and y in the formula with the values in xvar and yvar
formula <- as.formula(paste0(yvar, " ~ poly(", xvar, ", degree = ", input$degree, ")"))
keep_data <- data[vals$keeprows, , drop = FALSE]
# Return the kept points.
stopApp(
list(
data = keep_data,
model = lm(formula, keep_data)
)
)
})
}
runGadget(ui, server, viewer = dialogViewer("lmGadget")) # separate viewer window
}
lmGadget(geo_eccc_1, "Percentage_ns", "Composite_Index")
lmGadget(iris, "Sepal.Length", "Sepal.Width")
## [1] "Subregion" "Site"
## [3] "Proportion_of_native_species" "Cultural_species_richness"
## [5] "Exotic_species" "Trampling"
## [7] "Herbivory" "Composite_Index"
## 'data.frame': 24 obs. of 8 variables:
## $ Subregion : chr "Gulf Islands" "Gulf Islands" "Gulf Islands" "Gulf Islands" ...
## $ Site : chr "Anniversary Island" "AVNR" "Brackman Island" "Crows Nest" ...
## $ Proportion_of_native_species: num 0.94 0.55 0.77 0.66 0.75 0.53 0.45 0.65 0.62 0.58 ...
## $ Cultural_species_richness : num 2.71 1.3 2.8 1.07 3.6 0.8 0.42 2 3.6 2.33 ...
## $ Exotic_species : num 0.17 57.19 11.17 31.51 8.8 ...
## $ Trampling : num 5 4.7 5.4 1.64 12.2 ...
## $ Herbivory : num 1.14 36.5 0 26.71 0.1 ...
## $ Composite_Index : num 1.8 0.6 2 1 1.6 0.8 0.2 1.4 1 1 ...
##
## Listening on http://127.0.0.1:3924
app-leaflet-reactive-AllSiteDetails-WORKING
##
## Attaching package: 'bslib'
## The following object is masked from 'package:utils':
##
## page
## [1] "Subregion" "Site"
## [3] "Land_Manager" "Main_Restoration_Type"
## [5] "Restoration_Intensity" "Area_ha"
## [7] "Lat" "Lng"
## [9] "Proportion_of_native_species" "Cultural_species_richness"
## [11] "Exotic_species" "Trampling"
## [13] "Herbivory" "Composite_Index"
## 'data.frame': 24 obs. of 14 variables:
## $ Subregion : chr "Gulf Islands" "Gulf Islands" "Saanich Peninsula" "Gulf Islands" ...
## $ Site : chr " Anniversary Island" " AVNR" " Bear Hill Park" " Brackman Island" ...
## $ Land_Manager : chr " GINPR " " Saltspring conservancy" "CRD" " GINPR" ...
## $ Main_Restoration_Type : chr "herbivore reduction" " herbivore reduction" " invasive removal" " invasive removal" ...
## $ Restoration_Intensity : chr " high" " high" " low" " high" ...
## $ Area_ha : num 4.39 20.54 3.8 4.41 10.1 ...
## $ Lat : num 48.8 48.8 48.5 48.7 48.4 ...
## $ Lng : num -123 -123 -123 -123 -124 ...
## $ Proportion_of_native_species: num 0.94 0.55 0.62 0.77 0.61 0.66 0.75 0.53 0.32 0.64 ...
## $ Cultural_species_richness : num 2.71 1.3 1.86 2.8 2.43 1.07 3.6 0.8 1 4.4 ...
## $ Exotic_species : num 0.17 57.19 24.46 11.17 27.19 ...
## $ Trampling : num 5 4.7 7.57 5.4 7.71 1.64 12.2 16.6 10.4 6.2 ...
## $ Herbivory : num 1.14 36.5 9.5 0 4.71 ...
## $ Composite_Index : num 1.8 0.6 1 2 1.4 1 1.6 0.8 0.4 1.6 ...
##
## Listening on http://127.0.0.1:5517
app-datatable-search-plot-update-ECCC-TEST https://stackoverflow.com/questions/52880657/in-an-shiny-app-i-want-a-plot-to-update-based-on-the-search-results-in-a-datat
##
## Attaching package: 'DT'
## The following objects are masked from 'package:shiny':
##
## dataTableOutput, renderDataTable
##
## Listening on http://127.0.0.1:6009
### Plot Select Axis Variables app4-SelectAxisVariables-WORKS.R - this shiny app won’t knit - looses connection ???
##
## Attaching package: 'shinyscreenshot'
## The following object is masked from 'package:shiny':
##
## runExample
##
## Listening on http://127.0.0.1:7765
## [1] "Exotic_species"
## Warning in file(file, "rt"): cannot open file 'TEST-GOE-Monitor.csv': No such
## file or directory
## Warning: Error in file: cannot open the connection
## [1] "Proportion_of_native_species"
## Warning in file(file, "rt"): cannot open file 'TEST-GOE-Monitor.csv': No such
## file or directory
## Warning in file(file, "rt"): Error in file: cannot open the connection
geo_eccc <- read.csv("TEST-GOE-Monitor.csv", header = TRUE, sep = ",", stringsAsFactors=FALSE)
str(geo_eccc)
## 'data.frame': 24 obs. of 8 variables:
## $ Subregion : chr "Gulf Islands" "Gulf Islands" "Gulf Islands" "Gulf Islands" ...
## $ Site : chr "Anniversary Island" "AVNR" "Brackman Island" "Crows Nest" ...
## $ Proportion_of_native_species: num 0.94 0.55 0.77 0.66 0.75 0.53 0.45 0.65 0.62 0.58 ...
## $ Cultural_species_richness : num 2.71 1.3 2.8 1.07 3.6 0.8 0.42 2 3.6 2.33 ...
## $ Exotic_species : num 0.17 57.19 11.17 31.51 8.8 ...
## $ Trampling : num 5 4.7 5.4 1.64 12.2 ...
## $ Herbivory : num 1.14 36.5 0 26.71 0.1 ...
## $ Composite_Index : num 1.8 0.6 2 1 1.6 0.8 0.2 1.4 1 1 ...
names(geo_eccc)
## [1] "Subregion" "Site"
## [3] "Proportion_of_native_species" "Cultural_species_richness"
## [5] "Exotic_species" "Trampling"
## [7] "Herbivory" "Composite_Index"
subregion_var_violin <- function(file, title, subtitle, colx, coly, xlab, ylab, caption){
ggplot2::ggplot(file,
ggplot2::aes(x = colx, y = coly)) +
ggplot2::geom_violin(fill = "seagreen2") +
ggplot2::geom_boxplot(width = 0.1, fill = "sandybrown") +
ggplot2::theme_minimal() + #get rid of grey background and tick marks
ggplot2::theme(legend.position="none") + #remove legend
ggplot2::theme(
axis.text.x = ggplot2::element_text(vjust = 1, hjust = .5, size = 8),
axis.text.y = ggplot2::element_text(size = 5),
plot.title = ggplot2::element_text(hjust = 0.5, size = 12),
plot.subtitle = ggplot2::element_text(hjust = 0.5, size = 12)) +
#theme(axis.text.x = element_text(angle = 25, vjust = 1, hjust=1, size = 7)) +
ggplot2::labs(title=title,
subtitle=subtitle,
caption = caption,
x = xlab, y = ylab)
#subregion_exsp
}
subregion_var_violin(geo_eccc, 'Plotting Subregion by Exotic_species', 'ECCC Data Paper', geo_eccc$Subregion, geo_eccc$Exotic_species, "Subregion", "Exotic_species", "Chart by Wendy Anthony \n 2025-09-04")
subregion_var_violin(geo_eccc,'Plotting Subregion by Cultural_species_richness', 'ECCC Data Paper', geo_eccc$Subregion, geo_eccc$Cultural_species_richness, "Subregion", "Cultural_species_richness", "Chart by Wendy Anthony \n 2025-08-16")
geo_eccc <- read.csv("TEST-GOE-Monitor.csv", header = TRUE, sep = ",", stringsAsFactors=FALSE)
str(geo_eccc)
## 'data.frame': 24 obs. of 8 variables:
## $ Subregion : chr "Gulf Islands" "Gulf Islands" "Gulf Islands" "Gulf Islands" ...
## $ Site : chr "Anniversary Island" "AVNR" "Brackman Island" "Crows Nest" ...
## $ Proportion_of_native_species: num 0.94 0.55 0.77 0.66 0.75 0.53 0.45 0.65 0.62 0.58 ...
## $ Cultural_species_richness : num 2.71 1.3 2.8 1.07 3.6 0.8 0.42 2 3.6 2.33 ...
## $ Exotic_species : num 0.17 57.19 11.17 31.51 8.8 ...
## $ Trampling : num 5 4.7 5.4 1.64 12.2 ...
## $ Herbivory : num 1.14 36.5 0 26.71 0.1 ...
## $ Composite_Index : num 1.8 0.6 2 1 1.6 0.8 0.2 1.4 1 1 ...
names(geo_eccc)
## [1] "Subregion" "Site"
## [3] "Proportion_of_native_species" "Cultural_species_richness"
## [5] "Exotic_species" "Trampling"
## [7] "Herbivory" "Composite_Index"
subregion_var_point <- function(file, title, subtitle, colx, coly, xlab, ylab, caption){
ggplot(file,
aes(x = colx, y = coly, colour = Subregion)) +
geom_point(shape = 18, size = 2) +
theme_minimal() + #get rid of grey background and tick marks
theme(legend.position="bottom") +
# theme(legend.position="none") + #remove legend
theme(axis.text.x = element_text(angle =35, vjust = 1, hjust=1, size = 7)) +
labs(title=title,
subtitle=subtitle,
caption = caption,
x = xlab, y = ylab)
}
subregion_var_point(geo_eccc,'Plotting Site by Percentage Native Species', 'Malloff & Shackelford. (2024). \nFeeling the Pulse: Monitoring methods and initial outcomes in oak meadow ecosystems. \nRestoration Futures Lab at the University of Victoria.
', geo_eccc$Site, geo_eccc$Proportion_of_native_species, "Site", "Proportion of native species", "Chart by Wendy Anthony \n 2025-09-16 \n ECCC Data: (Malloff & Shackelford, 2024)")
subregion_var_point(geo_eccc,'Plotting Site by Exotic Species', 'Malloff & Shackelford. (2024). \nFeeling the Pulse: Monitoring methods and initial outcomes in oak meadow ecosystems. \nRestoration Futures Lab at the University of Victoria.
', geo_eccc$Site, geo_eccc$Exotic_species, "Site", "Exotic Species", "Chart by Wendy Anthony \n 2025-09-16 \n ECCC Data: (Malloff & Shackelford, 2024)")
Sites_eccc <- read.csv("SiteDetails-TEST-GOE-Monitor.csv", header = TRUE, sep = ",")
names(Sites_eccc)
## [1] "Subregion" "Site" "Land.Manager"
## [4] "Main.Restoration.Type" "Restoration.Intensity" "Area.ha"
## [7] "Lat" "Lng"
library(dplyr)
library(leaflet)
library(htmlwidgets) # for responsive web map
# custom icon
# https://leafletjs.com/examples/custom-icons/
greenLeafIcon <- makeIcon(
iconUrl = "https://leafletjs.com/examples/custom-icons/leaf-green.png",
iconWidth = 38, iconHeight = 95,
iconAnchorX = 22, iconAnchorY = 94,
shadowUrl = "https://leafletjs.com/examples/custom-icons/leaf-shadow.png",
shadowWidth = 50, shadowHeight = 64,
shadowAnchorX = 4, shadowAnchorY = 62
)
# change LeafIcon size 1/2
greenLeafIconSm <- makeIcon(
iconUrl = "https://leafletjs.com/examples/custom-icons/leaf-green.png",
iconWidth = 19, iconHeight = 47,
iconAnchorX = 11, iconAnchorY = 47,
shadowUrl = "https://leafletjs.com/examples/custom-icons/leaf-shadow.png",
shadowWidth = 25, shadowHeight = 32,
shadowAnchorX = 2, shadowAnchorY = 31
)
# Title control
title <- tags$div(HTML('<b>ECC Site Maps</b><br>Malloff & Shackelford. (2024). Feeling the Pulse: Monitoring methods and initial outcomes in oak meadow ecosystems. Restoration Futures Lab at the University of Victoria'))
ECCC_map <- leaflet(Sites_eccc) %>%
addProviderTiles("Esri.WorldImagery") %>%
addMarkers(
~ Lng, ~ Lat, icon = greenLeafIconSm,
popup = paste0("<b>Subregion:</b> ", Sites_eccc$Subregion, "<br>", "<b>Site:</b> ", Sites_eccc$Site, "<br>", "<b>Latitude:</b> ", Sites_eccc$Lat, "<br>", "<b>Longitude:</b> ", Sites_eccc$Lng, "<br><br>", "<b>Land Manager:</b> ", Sites_eccc$Land.Manager, "<br>", "<b>Main Restoration:</b> ", Sites_eccc$Main.Restoration.Type, "<br>", "<b>Restoration Intensity:</b> ", Sites_eccc$Restoration.Intensity, "<br>", "<b> Area:</b> ", Sites_eccc$Area.ha, " ha")) %>%
setView(-123.44799, 48.64919, 9) %>%
addMiniMap(width = 150, height = 150, zoomLevelOffset = -4) %>%
addControl(title, position = "topright")
# Display map
ECCC_map
# Save map
saveWidget(ECCC_map, "ECCC_map.html")
# NOT WORKING - Sites not same
#geo_eccc_sites <- cbind(geo_eccc, Sites_eccc)
# try to add , "<br>", "<b>Composite Index:</b> ", geo_eccc_sites$Composite_Index
# names(geo_eccc_sites)
names(Sites_eccc)
## [1] "Subregion" "Site" "Land.Manager"
## [4] "Main.Restoration.Type" "Restoration.Intensity" "Area.ha"
## [7] "Lat" "Lng"
library(dplyr)
library(leaflet)
library(htmlwidgets) # for responsive web map
# Title control
title <- tags$div(HTML('<b>ECC Site Maps</b><br>Malloff & Shackelford. (2024). Feeling the Pulse: Monitoring methods and initial outcomes in oak meadow ecosystems. Restoration Futures Lab at the University of Victoria'))
# https://rstudio.github.io/leaflet/articles/markers.html
# Create a palette that maps factor levels to colors
pal <- colorFactor(c("green", "orange"), domain = c("Saanich Peninsula", "Gulf Islands"))
ECCC_map <- leaflet(Sites_eccc) %>%
addProviderTiles("Esri.WorldImagery") %>%
addCircleMarkers(
~ Lng, ~ Lat, radius = ~ifelse(Subregion == "Saanich Peninsula", 4, 5),
color = ~pal(Subregion),
stroke = FALSE, fillOpacity = 0.5,
popup = paste0("<b>Site:</b> ", Sites_eccc$Site, "<br>", "<b>Subregion:</b> ", Sites_eccc$Subregion, "<br>", "<b>Latitude:</b> ", Sites_eccc$Lat, "<br>", "<b>Longitude:</b> ", Sites_eccc$Lng, "<br><br>", "<b>Land Manager:</b> ", Sites_eccc$Land.Manager, "<br>", "<b>Main Restoration:</b> ", Sites_eccc$Main.Restoration.Type, "<br>", "<b>Restoration Intensity:</b> ", Sites_eccc$Restoration.Intensity, "<br>", "<b> Area:</b> ", Sites_eccc$Area.ha, " ha")) %>%
setView(-123.44799, 48.64919, 9) %>%
addMiniMap(width = 150, height = 150, zoomLevelOffset = -4) %>%
addControl(title, position = "topright")
# Display map
ECCC_map
# Save map
saveWidget(ECCC_map, "ECCC_map.html")
# NOT WORKING - Sites not same
#geo_eccc_sites <- cbind(geo_eccc, Sites_eccc)
# try to add , "<br>", "<b>Composite Index:</b> ", geo_eccc_sites$Composite_Index
# names(geo_eccc_sites)
names(Sites_eccc)
## [1] "Subregion" "Site" "Land.Manager"
## [4] "Main.Restoration.Type" "Restoration.Intensity" "Area.ha"
## [7] "Lat" "Lng"
library(dplyr)
library(leaflet)
library(htmlwidgets) # for responsive web map
# Title control
# Malloff & Shackelford. (2024). Feeling the Pulse: Monitoring methods and initial outcomes in oak meadow ecosystems. Restoration Futures Lab at the University of Victoria
title <- tags$div(HTML('<p style="font-size:12px;font-weight:bold">ECC Sites Map</p>'))
# https://rstudio.github.io/leaflet/articles/markers.html
# Create a palette that maps factor levels to colors
pal <- colorFactor(c("green", "orange"), domain = c("Saanich Peninsula", "Gulf Islands"))
ECCC_map <- leaflet(Sites_eccc) %>%
addProviderTiles("Esri.WorldImagery") %>%
addCircleMarkers(
~ Lng, ~ Lat,
# https://stackoverflow.com/questions/40137212/variable-marker-size-feature-in-leaflet-r
radius = ~geo_eccc$Composite_Index * 3,
# radius = ~Sites_eccc$Area.ha,
# radius = ~sqrt(Sites_eccc$Area.ha),
# size smaller is Saanich, else larger if Gulf
# radius = ~ifelse(Subregion == "Saanich Peninsula", 4, 5),
color = ~pal(Subregion),
stroke = FALSE, fillOpacity = 0.5,
popup = paste0("<b>Site:</b> ", Sites_eccc$Site, "<br>", "<b>Subregion:</b> ", Sites_eccc$Subregion, "<br>", "<b>Latitude:</b> ", Sites_eccc$Lat, "<br>", "<b>Longitude:</b> ", Sites_eccc$Lng, "<br><br>", "<b>Land Manager:</b> ", Sites_eccc$Land.Manager, "<br>", "<b>Main Restoration:</b> ", Sites_eccc$Main.Restoration.Type, "<br>", "<b>Restoration Intensity:</b> ", Sites_eccc$Restoration.Intensity, "<br>", "<b> Area:</b> ", Sites_eccc$Area.ha, " ha")) %>%
setView(-123.44799, 48.64919, 9) %>%
addMiniMap(width = 150, height = 150, zoomLevelOffset = -4) %>%
addControl(title, position = "topright")
# Display map
ECCC_map
# Save map
saveWidget(ECCC_map, "ECCC_map.html")
geo_eccc_all_site_data.csv
geo_eccc_sites_1 <- read.csv("geo_eccc_all_site_data.csv")
names(geo_eccc_sites_1)
## [1] "Subregion" "Site"
## [3] "Land_Manager" "Main_Restoration_Type"
## [5] "Restoration_Intensity" "Area_ha"
## [7] "Lat" "Lng"
## [9] "Proportion_of_native_species" "Cultural_species_richness"
## [11] "Exotic_species" "Trampling"
## [13] "Herbivory" "Composite_Index"
library(dplyr)
library(leaflet)
library(htmlwidgets) # for responsive web map
# Title control
# Malloff & Shackelford. (2024). Feeling the Pulse: Monitoring methods and initial outcomes in oak meadow ecosystems. Restoration Futures Lab at the University of Victoria
title <- tags$div(HTML('<p style="font-size:12px;font-weight:bold">ECC Sites Map</p>'))
# https://rstudio.github.io/leaflet/articles/markers.html
# Create a palette that maps factor levels to colors
pal <- colorFactor(c("#d7191c", "#2c7bb6"), domain = c("Saanich Peninsula", "Gulf Islands"))
ECCC_map_1 <- leaflet(geo_eccc_sites_1) %>%
addProviderTiles("Esri.WorldImagery") %>%
addCircleMarkers(
~ Lng, ~ Lat,
# https://stackoverflow.com/questions/40137212/variable-marker-size-feature-in-leaflet-r
radius = ~geo_eccc_sites_1$Composite_Index * 5,
# radius = ~geo_eccc_sites_1$Area.ha,
# radius = ~sqrt(geo_eccc_sites_1$Area.ha),
# size smaller is Saanich, else larger if Gulf
# radius = ~ifelse(Subregion == "Saanich Peninsula", 4, 5),
fillColor = ~pal(Subregion),
color = "black",
weight = 3, # size of circle border
stroke = TRUE, fillOpacity = 0.5,
popup = paste0("<b>Site:</b> ", "<b>", "<b>", geo_eccc_sites_1$Site, "</b>", "</b>", "<br><br>", "<b>Subregion:</b> ", geo_eccc_sites_1$Subregion, "<br>",
"<b>Latitude:</b> ", geo_eccc_sites_1$Lat, "<br>", "<b>Longitude:</b> ", geo_eccc_sites_1$Lng, "<br><br>",
"<b>Land Manager:</b> ", geo_eccc_sites_1$Land_Manager, "<br>",
"<b>Main Restoration:</b> ", geo_eccc_sites_1$Main_Restoration_Type, "<br>",
"<b>Restoration Intensity:</b> ", geo_eccc_sites_1$Restoration_Intensity, "<br>",
"<b> Area:</b> ", geo_eccc_sites_1$Area_ha, " ha",
"<br><br>",
"<b>Proportion of native species:</b> ", geo_eccc_sites_1$Proportion_of_native_species, "<br>",
"<b>Cultural species richness:</b> ", geo_eccc_sites_1$Cultural_species_richness, "<br>",
"<b>Exotic species:</b> ", geo_eccc_sites_1$Exotic_species, "<br>",
"<b>Trampling:</b> ", geo_eccc_sites_1$Trampling, "<br>",
"<b>Herbivory:</b> ", geo_eccc_sites_1$Herbivory, "<br>",
"<b>Composite Index:</b> ", geo_eccc_sites_1$Composite_Index, "<br>")) %>%
setView(-123.44799, 48.64919, 10) %>%
addMiniMap(width = 150, height = 150, zoomLevelOffset = -4) %>%
addControl(title, position = "topright")
# Display map
ECCC_map_1
# Save map
saveWidget(ECCC_map_1, "ECCC_map_CI.html")
# to document specific packages used to run script
sessionInfo()
## R version 4.2.1 (2022-06-23)
## Platform: x86_64-apple-darwin17.0 (64-bit)
## Running under: macOS Mojave 10.14.6
##
## Matrix products: default
## BLAS: /Library/Frameworks/R.framework/Versions/4.2/Resources/lib/libRblas.0.dylib
## LAPACK: /Library/Frameworks/R.framework/Versions/4.2/Resources/lib/libRlapack.dylib
##
## locale:
## [1] en_CA.UTF-8/en_CA.UTF-8/en_CA.UTF-8/C/en_CA.UTF-8/en_CA.UTF-8
##
## attached base packages:
## [1] stats graphics grDevices utils datasets methods base
##
## other attached packages:
## [1] htmlwidgets_1.5.4 shinyscreenshot_0.2.0 DT_0.26
## [4] leaflet_2.1.1 bslib_0.4.0 forcats_0.5.2
## [7] stringr_1.4.1 dplyr_1.0.10 purrr_0.3.5
## [10] readr_2.1.3 tidyr_1.2.1 tibble_3.1.8
## [13] ggplot2_3.4.0 tidyverse_1.3.2 shiny_1.7.3
##
## loaded via a namespace (and not attached):
## [1] fs_1.5.2 lubridate_1.8.0 fontawesome_0.4.0
## [4] webshot_0.5.4 httr_1.4.4 tools_4.2.1
## [7] backports_1.4.1 utf8_1.2.2 R6_2.5.1
## [10] DBI_1.1.3 colorspace_2.0-3 withr_2.5.0
## [13] tidyselect_1.2.0 processx_3.7.0 compiler_4.2.1
## [16] textshaping_0.3.6 cli_3.4.1 rvest_1.0.3
## [19] xml2_1.3.3 labeling_0.4.2 sass_0.4.2
## [22] scales_1.2.1 callr_3.7.2 systemfonts_1.0.4
## [25] digest_0.6.30 rmarkdown_2.17 pkgconfig_2.0.3
## [28] htmltools_0.5.3 dbplyr_2.2.1 fastmap_1.1.0
## [31] highr_0.9 rlang_1.0.6 readxl_1.4.1
## [34] rstudioapi_0.14 jquerylib_0.1.4 farver_2.1.1
## [37] generics_0.1.3 jsonlite_1.8.2 crosstalk_1.2.0
## [40] googlesheets4_1.0.1 magrittr_2.0.3 Rcpp_1.0.9
## [43] munsell_0.5.0 fansi_1.0.3 lifecycle_1.0.3
## [46] stringi_1.7.8 yaml_2.3.5 grid_4.2.1
## [49] promises_1.2.0.1 crayon_1.5.2 haven_2.5.1
## [52] hms_1.1.2 knitr_1.40 ps_1.7.1
## [55] pillar_1.8.1 uuid_1.1-0 markdown_1.1
## [58] reprex_2.0.2 glue_1.6.2 evaluate_0.17
## [61] leaflet.providers_1.9.0 modelr_0.1.9 vctrs_0.5.0
## [64] tzdb_0.3.0 httpuv_1.6.6 cellranger_1.1.0
## [67] gtable_0.3.1 assertthat_0.2.1 cachem_1.0.6
## [70] xfun_0.37 mime_0.12 xtable_1.8-4
## [73] broom_1.0.1 later_1.3.0 ragg_1.2.3
## [76] googledrive_2.0.0 gargle_1.2.1 memoise_2.0.1
## [79] ellipsis_0.3.2